package com.chensf.studydemo.extensions

import android.content.Context
import android.os.Environment
import java.io.File

fun isExistSDCard(): Boolean =
    Environment.getExternalStorageState() == Environment.MEDIA_MOUNTED // 判断sd卡是否存在


val Context.diskCachePath: String
    get() {
        return if (isExistSDCard() && externalCacheDir != null) {
            externalCacheDir!!.path
        } else {
            cacheDir.path
        }
    }

val Context.tempCacheDir: File
    get() {
        val dir = File("$diskCachePath${File.separator}temp")
        if (!dir.exists()) {
            dir.mkdir()
        }
        return dir
    }